package com.leezt.designpattern.principles.OCP.services;

import com.leezt.designpattern.principles.OCP.models.AlertRule;

import java.util.ArrayList;
import java.util.List;

public class AlertRuleManager {
    private final List<AlertRule> rules;

    public AlertRuleManager() {
        rules = new ArrayList<>();
    }
    public AlertRuleManager(List<AlertRule> rules) {
        this.rules = rules;
    }

    public void addAlertRule(AlertRule rule) {
        rules.add(rule);
    }

    public AlertRule getMatchedRule(String api) {
        return rules.stream().filter(rule -> api.equals(rule.getApi())).findAny().orElse(null);
    }
}
